import fire from '@dfeidao/atom-web/msg/fire';
import javadsd from '@dfeidao/atom-web/msg/javadsd';
import error from '@dfeidao/atom-web/msgbox/error';
import success from '@dfeidao/atom-web/msgbox/success';
import s_get from '@dfeidao/atom-web/storage/get';
import Tree from '@dfeidao/fd-w000001';
import { IFeidaoAiBrowserComponent } from '@dfeidao/web/interfaces';

export default async function a005(fd: IFeidaoAiBrowserComponent, args: Event) {
	const productid = await s_get('productid');
	//  保存
	// const no1 = args[1];
	// const no = args[0];
	// const formgroup_no = no;
	// console.log(args, '---', args[0], '---', args[1]);
	const formgroup_no = args;
	const client_type = fd.data.node.querySelector<HTMLSelectElement>('[data-feidao-id="client_style"]').value;

	const widget: Tree = document.querySelector('#widget');

	// 取树形图数据
	const v = fd.data.node.querySelector<Tree>('#widget').get_checked();
	const rea = new Array();
	v.forEach((item) => {
		rea.push(item.id);
	});
	const rey = new Array();
	v.forEach((item) => {
		rey.push(item.p_id);
	});

	widget.check_node(rey);
	const v_1 = fd.data.node.querySelector<Tree>('#widget').get_checked();
	const rea1 = new Array();
	v_1.forEach((item) => {
		rea1.push(item.id);
	});
	const rey_1 = new Array();
	v_1.forEach((item) => {
		rey_1.push(item.p_id);
	});
	widget.check_node(rey_1);
	const v_2 = fd.data.node.querySelector<Tree>('#widget').get_checked();
	const rea2 = new Array();
	v_2.forEach((item) => {
		rea2.push(item.id);
	});
	if (!formgroup_no) {
		error("请先选择一行数据");
	} else {

		const menu_no = rea2.toString();
		const condition = { param: { client_type, formgroup_no, menu_no, productid } };
		// debugger;

		const data: { code: number } = await javadsd('12', '', 'feidao_400dsd0000005', condition);
		if (data.code === 1) {
			success("保存成功");
			// fire('zj-000002', 'ec-002', no1);

			fire('zj-000002', 'a003', formgroup_no);
		} else {
			error("保存失败");

		}
	}

}
